using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using NHibernate.Expression;
using Saffron.Framework.Users;


namespace Saffron.Framework.Messages
{
    [ActiveRecord]
    public class MessageInfo : ActiveRecordBase
    {
       
        private int _id = 0;
        private UserAccount _sentTo;
        private Message _sentMessage;
        private bool _viewed = false;

        [PrimaryKey]
        public int Id
        {
            get { return _id; }
            set{_id = value;}
        }


        [BelongsTo("SentTo", NotNull = true)]
        public UserAccount SentTo
        {
            get { return _sentTo; }
            set { _sentTo = value; }
        }
        [BelongsTo("SentMessage", NotNull = true)]
        public Message SentMessage
        {
            get { return _sentMessage; }
            set { _sentMessage = value; }
        }

        [Property(NotNull = true)]
        public bool Viewed
        {
            get { return _viewed; }
            set { _viewed = value; }
        }


        public static MessageInfo [] FindMessageInfoListByUser(UserAccount user)
        {
           return (MessageInfo [] )MessageInfo.FindAllByProperty(typeof(MessageInfo), "SentTo", user);  
        }
        public static MessageInfo FindMessageInfoById(int id)
        {
            return (MessageInfo)FindByPrimaryKey(typeof(MessageInfo),id);
        }
    }
}
